package emergent;

public abstract class Agent implements Runnable{
    int id;
	protected boolean alive = true;
	protected int procrastination;
	protected Monitor supervisor;
	protected int myRow;
	protected int myColumn;
	protected Agent[][] agents;
	protected boolean syncMode = true;
	
	
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public boolean isAlive() {
		return alive;
	}

	public void setAlive(boolean alive) {
		this.alive = alive;
	}

	public int getProcrastination() {
		return procrastination;
	}

	public void setProcrastination(int procrastination) {
		this.procrastination = procrastination;
	}

	public Monitor getSupervisor() {
		return supervisor;
	}

	public void setSupervisor(Monitor supervisor) {
		this.supervisor = supervisor;
	}

	public int getMyRow() {
		return myRow;
	}

	public void setMyRow(int myRow) {
		this.myRow = myRow;
	}

	public int getMyColumn() {
		return myColumn;
	}

	public void setMyColumn(int myColumn) {
		this.myColumn = myColumn;
	}

	public Agent (int id, Monitor supervisor, boolean sync){
		this.syncMode = sync;
		this.alive = true;
		this.id = id;
		this.procrastination = 1 + (int)(Math.random() * 100d);
		this.supervisor = supervisor;
	}
	
	public Agent(int id, Monitor supervisor, boolean sync, boolean useRandomDelay, int min , int max){
		this.alive = true;
		this.syncMode = sync;
		this.id = id;
		this.procrastination = (int)(min + Math.random() * (double)(max-min));
		this.supervisor = supervisor;

	}
	
	public Agent(int id, Monitor supervisor, boolean sync, int procrastination){
		this.syncMode = sync;
		this.alive = true;
		this.id = id;
		this.procrastination = procrastination;
		this.supervisor = supervisor;
	}
	
	public void kill(){
		alive = false;
	}
	
	
	public abstract String toString();

	@Override
	public void run() {
		//System.out.println("alive" + id);
			while(alive){
		if ((supervisor.getWorld().getTime() % procrastination) == 0){
			supervisor.getWorld().act(this);
		}
		if (syncMode) supervisor.checkin(this);
	}
		
	}

}
